﻿using KeyStone.Ioc;
using KeyStone.Ioc.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IocContainerExample.TestHarness
{
   public class Example4
   {
      public Example4()
      {
         IIocContainer container = new IocContainer();
         container.Register<IMyExample4, MyExample4>();
         container.Register<IMyExample4a, MyExample4a>();
         container.Register<IMyExample4b, MyExample4b>();

         // constructor injection and property injection
         IMyExample4 temp = container.Resolve<IMyExample4>();
         
         
         Console.WriteLine("Example 4 : {0} , {1}" ,temp.Text, temp.Dates.Date);
      }

   }
   
   public interface IMyExample4
   {
      string Text { get; set; }
      IMyExample4b Dates { get; set; } 
   }

   public class MyExample4 : IMyExample4
   {
      [Dependency]
      public IMyExample4b Dates { get; set; }

      public MyExample4(IMyExample4a value)
      {
         Text = string.Format("hello {0}", value.Total);
      }

      public string Text { get; set; }
   }

   public interface IMyExample4a
   {
      int Total { get; set; }
   }

   public class MyExample4a : IMyExample4a
   {
      public MyExample4a()
      {
         Total = 1234;
      }

      public int Total { get; set; }
   }

   public interface IMyExample4b
   {
      DateTime Date { get; set; }
   }

   public class MyExample4b : IMyExample4b
   {
      public MyExample4b()
      {
         Date = DateTime.Now;
      }
      public DateTime Date { get; set; }
   }
}
